﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessTier;
using System.Data;

public partial class AddToGroup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UserNameHiddenField.Value = HttpContext.Current.User.Identity.Name;
        
            //BusinessTier.Review data = new BusinessTier.Review(HttpContext.Current.User.Identity.Name.ToString());

            //// Check if authenticated student is in group
            //bool isInGroup = data.isInGroup();

            //// If current student isn't in group - redirect to StudentDetails.aspx
            //// Otherwise page is loaded
            //if (!isInGroup)
            //{
            //    Response.Redirect("../Student/StudentDetails.aspx");
            //}
            //else
            //{
            //    GroupNameLabel.Text = data.getGroupName();
            //    DataTable students = data.groupDetails();

            //    // counter initialised for foreach loop
            //    int counter = 2;

            //    // ContentPlaceHolder object is used by master pages to store 
            //    // user specified content, here we initialise an emtpy instance
            //    ContentPlaceHolder contentPlaceHolder;

            //    // We now look for the main body of our page using FindControl() 
            //    // (which returns an aspx control) on the master object (i.e. the page in question). 
            //    // This is type casted as a ContentPlaceHolder object then stored in the 
            //    // pre-initialised object above
            //    contentPlaceHolder = (ContentPlaceHolder)Master.FindControl("pagebody");

            //    // Text box objects are initialised to use as references for the username 
            //    // and user ID text boxes on page
            //    TextBox userNameTextBox;
            //    TextBox userIDTextBox;
            //    TextBox userPhoneTextBox;
            //    TextBox userEmailTextBox;

            //    // loop runs through the rows (i.e. the records) stored in DataTable object 'students'
            //    foreach (DataRow row in students.Rows)
            //    {
            //        if (row["user_id"].ToString() != HttpContext.Current.User.Identity.Name.ToString())
            //        {
            //            // This part only runs for the other group members i.e.: not the current student
            //            // i.e.: only if the student number of this record doesnt match the student 
            //            // number of the currently authenticated student
            //            // ---
            //            // How it works: 
            //            // With each loop there is a new text box stored in the objects initialise above
            //            // (i.e. userNameTextBox and userIDTextBox), these are found by using FindControl()
            //            // on the ContentPlaceHolder object then type casted as a text box.
            //            // The data in columns [user_name] and [user_id] of this record is then set to the text
            //            // of their respective text boxes. These text boxes are then disabled so they can't
            //            // be changed by the user. 
            //            // Finally the counter is incremented - you may notice that as part of the argument
            //            // in the the FindControl() calls that the counter is appended. This ensures that
            //            // each loop looks for the next text box e.g.: Loop 1 = StudentNameTextBox2, 
            //            // Loop 2 = StudentNameTextBox3 etc. You may also notice that we start at text box 2,
            //            // this is because the first text box belongs to the current user.
            //            userNameTextBox = (TextBox)contentPlaceHolder.FindControl("StudentNameTextBox" + counter.ToString());
            //            userIDTextBox = (TextBox)contentPlaceHolder.FindControl("StudentNumberTextBox" + counter.ToString());
            //            userPhoneTextBox = (TextBox)contentPlaceHolder.FindControl("StudentPhoneTextBox" + counter.ToString());
            //            userEmailTextBox = (TextBox)contentPlaceHolder.FindControl("StudentEmailTextBox" + counter.ToString());
            //            userNameTextBox.Text = row["user_name"].ToString();
            //            userIDTextBox.Text = row["user_id"].ToString();
            //            userIDTextBox.Text = row["phone_number"].ToString();
            //            userIDTextBox.Text = row["email"].ToString();
            //            userNameTextBox.Enabled = false;
            //            userIDTextBox.Enabled = false;
            //            //userPhoneTextBox.Enabled = false;
            //            //userEmailTextBox.Enabled = false;
            //            counter++;
            //        }
            //        else
            //        {
            //            // When the record's user ID matches that of the current user the same actions
            //            // performed above is done but for the first text box. This is because the first
            //            // text box is allocated for self reflection.
            //            userNameTextBox = (TextBox)contentPlaceHolder.FindControl("StudentNameTextBox1");
            //            userIDTextBox = (TextBox)contentPlaceHolder.FindControl("StudentNumberTextBox1");
            //            userPhoneTextBox = (TextBox)contentPlaceHolder.FindControl("StudentPhoneTextBox1");
            //            userEmailTextBox = (TextBox)contentPlaceHolder.FindControl("StudentEmailTextBox1");
            //            userNameTextBox.Text = row["user_name"].ToString();
            //            userIDTextBox.Text = row["user_id"].ToString();
            //            userIDTextBox.Text = row["phone_number"].ToString();
            //            userIDTextBox.Text = row["email"].ToString();
            //            userNameTextBox.Enabled = false;
            //            userIDTextBox.Enabled = false;
            //            userPhoneTextBox.Enabled = false;
            //            userEmailTextBox.Enabled = false;
            //        } // end if else
            //    } // end foreach
            //} // end if else
        } // end Page_Load
    

    protected void WithdrawGroupsButton_Click(object sender, EventArgs e)
    {
        Memberships.withdrawGroup(HttpContext.Current.User.Identity.Name);
        Response.Redirect("~/Student/StudentDetails.aspx");
    }
}